package com.ruoyi.funding.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.funding.mapper.FundingResearchMapper;
import com.ruoyi.funding.domain.FundingResearch;
import com.ruoyi.funding.service.IFundingResearchService;

import static com.ruoyi.common.core.context.SecurityContextHolder.getUserName;

/**
 * 科研经费Service业务层处理
 * 
 * @author ycl
 * @date 2025-01-06
 */
@Service
public class FundingResearchServiceImpl implements IFundingResearchService 
{
    @Autowired
    private FundingResearchMapper fundingResearchMapper;

    /**
     * 查询科研经费
     * 
     * @param fundingId 科研经费主键
     * @return 科研经费
     */
    @Override
    public FundingResearch selectFundingResearchByFundingId(Long fundingId)
    {
        return fundingResearchMapper.selectFundingResearchByFundingId(fundingId);
    }

    /**
     * 查询科研经费列表
     * 
     * @param fundingResearch 科研经费
     * @return 科研经费
     */
    @Override
    public List<FundingResearch> selectFundingResearchList(FundingResearch fundingResearch)
    {
        return fundingResearchMapper.selectFundingResearchList(fundingResearch);
    }

    /**
     * 新增科研经费
     * 
     * @param fundingResearch 科研经费
     * @return 结果
     */
    @Override
    public int insertFundingResearch(FundingResearch fundingResearch)
    {
        fundingResearch.setCreateTime(DateUtils.getNowDate());
        fundingResearch.setCreateBy(getUserName());
        return fundingResearchMapper.insertFundingResearch(fundingResearch);
    }

    /**
     * 修改科研经费
     * 
     * @param fundingResearch 科研经费
     * @return 结果
     */
    @Override
    public int updateFundingResearch(FundingResearch fundingResearch)
    {
        fundingResearch.setUpdateTime(DateUtils.getNowDate());
        fundingResearch.setUpdateBy(getUserName());
        return fundingResearchMapper.updateFundingResearch(fundingResearch);
    }

    /**
     * 批量删除科研经费
     * 
     * @param fundingIds 需要删除的科研经费主键
     * @return 结果
     */
    @Override
    public int deleteFundingResearchByFundingIds(Long[] fundingIds)
    {
        for (Long id : fundingIds){
            FundingResearch fundingResearch = fundingResearchMapper.selectFundingResearchByFundingId(id);
            fundingResearch.setDeleteBy(getUserName());
            fundingResearch.setDeleteTime(DateUtils.getNowDate());
            fundingResearchMapper.updateFundingResearch(fundingResearch);
        }
        return fundingResearchMapper.deleteFundingResearchByFundingIds(fundingIds);
    }

    /**
     * 删除科研经费信息
     * 
     * @param fundingId 科研经费主键
     * @return 结果
     */
    @Override
    public int deleteFundingResearchByFundingId(Long fundingId)
    {
        FundingResearch fundingResearch = fundingResearchMapper.selectFundingResearchByFundingId(fundingId);
        fundingResearch.setDeleteBy(getUserName());
        fundingResearch.setDeleteTime(DateUtils.getNowDate());
        fundingResearchMapper.updateFundingResearch(fundingResearch);

        return fundingResearchMapper.deleteFundingResearchByFundingId(fundingId);
    }
}
